﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using SBACN.WebSite.Models;
using SBACN.WebSite.Code;

namespace SBACN.WebSite.ContentDL
{
	public partial class PolicyAnswerList : MemberBasePage
	{
		protected string Img { get; set; }
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BindData(1, "");
			}
			ImgData();
		}

		protected void BindData(int pageIndex, string tit)
		{
			Expression<Func<TB_News, bool>> f;
			if (string.IsNullOrWhiteSpace(tit))
			{
				f = (p => p.Type == this.SystemCode && !p.IsEn);
			}
			else
			{
				this.Txt_ID.Text = tit;
				f = (p => p.Type == this.SystemCode && (p.Title.Contains(tit) || p.Summary.Contains(tit)) && !p.IsEn);
			}

			int records = 0;

			Expression<Func<TB_News, DateTime>> order = (c => c.CreateDate);
			var resultC = DAL.DALHelper.Instance.GetList<TB_News, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);

			this.CouncilList.DataSource = resultC;
			this.CouncilList.DataBind();
			this.Pager1.RecordCount = records;
			this.Pager1.InitControl();

		}

		protected void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
		{
			string tit = "";
			if (!string.IsNullOrWhiteSpace(this.Txt_ID.Text))
			{
				tit = this.Txt_ID.Text;
			}
			BindData(nextPage, tit);
		}

		protected void ImgData()
		{
			string type;
			if (string.IsNullOrWhiteSpace(this.SystemCode))
			{
				type = "";
			}
			else
			{
				type = this.SystemCode;
			}
			Expression<Func<TB_SystemConfig, bool>> f = (p => p.Code == "Img" && p.Type == type);
			var resultQ = DAL.DALHelper.Instance.GetFirstOrDefaultObject<TB_SystemConfig>(f);
			if (resultQ != null)
			{
				this.Img = resultQ.Value.ToString();
			}
		}

		protected void btn_Search_Click(object sender, EventArgs e)
		{
			string tit = "";
			if (!string.IsNullOrWhiteSpace(this.Txt_ID.Text))
			{
				tit = this.Txt_ID.Text;
			}

			BindData(1, tit);
		}

	}
}